$(function() {
	app = new Vue({
		el : '#app',
		data : {
		},
		methods : {
			save : function() {
				var data = $('#form').serialize();
				/*var selectedclassifyIds = $("#shopclassifyName").find("option");
				for(var j = 0; j < selectedclassifyIds.length; j++) {
					data += "&integralShopClassify["+j+"].id=" + $(selectedclassifyIds[j]).prop("value");
				}	*/
				
				if ($("#shopclassifyIds").val() != "") {
					var shopclassifyIds = $("#shopclassifyIds").val().split(",");
					for(var i = 0; i < shopclassifyIds.length; i++) {
						data += "&integralShopClassify["+i+"].id=" + shopclassifyIds[i];
					}
				}
				console.log(data);
				$.ajax({
					type : "POST",
					url : '/manager/commodity/save',
					data : data,
					beforeSend : function() {

					},
					complete : function() {

					},
					error : function(request) {
						layer.alert("系统出错");
					},
					success : function(data) {
						if (data.status == 0) {
							refreshParentList();
							layer.alert(data.message, function() {
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
						}else{
							layer.alert(data.message);
						}
					}
				});
			},
			getIdFromUrl:function(){
				var addr = location.href;
				var index = addr.lastIndexOf('/') + 1;
				var id = addr.substr(index);
				return id;
			},
			init : function() {
				  var ue = UE.getEditor('container');

				_self = this;
				$("#form").validate({
					rules : {
						name : {
							required : true
						},
						integralPrice : {
							required : true
						},
						marketPrice : {
							required : true
						},
						status : {
							required : true
						},
						showImgs: {
							required : true
						},
						shopclassifyId: {
							required : true
						}
					},
					onkeyup : false,
					focusCleanup : true,
					success : "valid",
					submitHandler : function(form) {
						_self.save();
					}
				});
			}
		}
	});
	
	app.init();
});